package com.zmx.b2c.order.common;

import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description: CompletableFuture使用的线程池
 * @ClassName: CompletableFutureThreadPool
 * @Author zhaomxr
 * @Date 2022-01-07 16:05
 */
public class CompletableFutureThreadPool {

    final int poolSize = Runtime.getRuntime().availableProcessors();

    public ThreadPoolExecutor poolExecutor() {
        return poolExecutor(500);
    }

    public ThreadPoolExecutor poolExecutor(int capacity) {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                poolSize,
                100,
                60L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(capacity));

        return poolExecutor;
    }
}
